home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / MWCC03.ZIP / MDITOOL.ZIP / MDITOOL.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-18  |  25KB  |  742 lines

  1. {**********************************************************************}
  2. {*                                                                    *}
  3. {*          Microworks Sample Application                                        *}
  4. {*                                                                    *}
  5. {*         for Borland Pascal v7.0 and Turbo Pascal for Windows v1.5           *}
  6. {*                                                                    *}
  7. {*     Copyright 1992-93 Jeff Franks (Microworks) Sydney, Australia.  *}
  8. {*                                                                    *}
  9. {*         You are free to use, modify, reproduce and distribute the      *}
  10. {*         Sample Files (and/or any modified version) in any way you      *}
  11. {*         find useful.                                                                *}
  12. {*                                                                    *}
  13. {**********************************************************************}
  14.  
  15. {*** Introduction
  16.  
  17.     Application    := MDI Window with moveable tool bar.
  18.  
  19.     Files          := MDITool.pas, MDITool.res
  20.  
  21.     Units Required := FileDlg, MObjects, MCommDlg and MWCC.dll
  22.  
  23.     Purpose        := MDITool shows you how to,
  24.  
  25.                                     1. Set up a moveable toolbar in a MDI window.
  26.  
  27.                                         2. Use an SFX 'file open' and an MWCC 'file save as' dialog box.
  28.  
  29.                                         3. Use an MWCC 'Font' common dialog box.
  30.  
  31.                                         4. Use some of the button and static objects in the MWCC library.
  32.  
  33.     Tabs           := 2
  34.  
  35.     Screen         := 800 * 600
  36.                 
  37.     Date           := August 1993.
  38.  
  39.     This updated version of MDITool adds one of the new common Font dialog boxes (TMWCCFontDlg)
  40.     and shows off one of the new buttons, the Font button, that replaces the Find button (the eye)
  41.     in earlier versions.
  42.  
  43.     MDITool shows you how to set up a moveable tool bar in a MDI window without going
  44.     to all the code that the 'MFileApp' toolbar sample in BP 7.0 does (all 39K of it).
  45.     MDITool is a streamlined piece of code (12K) that accomplishes the same thing without
  46.     using separate objects for the toolbar and each tool.
  47.  
  48.     I didn't add anything else like an editor etc., you can do that. I wanted to keep it
  49.     simple, only showing you how to set up a moveable toolbar and use some of the standard
  50.     MWCC buttons and objects.
  51.  
  52.     You can add a status bar in the same way as the toolbar eg. by using a raised TMWCCStatic
  53.     object, a text TMWCCStatic object and shortening the height of the client area.
  54.  
  55.     TMWCCBmpButton is a Borland Style (3 bitmaps) button object. If you want a smaller toolbar
  56.     just create your own bitmaps, two or three for TMWCCBmpButton or one for TMWCCButton.
  57.  
  58. ***}
  59.  
  60. program MDITool;
  61.  
  62. {$R MDITool.res}
  63.  
  64. uses WinTypes, WinProcs, WinDos, Win31, Strings, ToolHelp, CommDlg,
  65.          MObjects, MMsgBox, MCommDlg, FileDlg,
  66.          {$IFDEF Ver15}
  67.              WObjects;
  68.          {$ELSE}
  69.              Objects, OWindows, ODialogs;
  70.          {$ENDIF}
  71.  
  72. const
  73.  
  74.     {*** Toolbar Constants ***}
  75.     ctl_Top          = 101;
  76.     ctl_Left         = 102;
  77.     ctl_Right        = 103;
  78.  
  79.     {*** Button ID's ***}
  80.     idw_But1         = 201;
  81.     idw_But2         = 202;
  82.     idw_But3         = 203;
  83.     idw_But4         = 204;
  84.     idw_But5         = 205;
  85.     idw_But6         = 206;
  86.  
  87.     {*** Static ID ***}
  88.     idw_Stat1        = 401;
  89.     idd_Stat1        = 402;
  90.     idd_Stat2        = 403;
  91.  
  92.     {*** Option Menu ID's ***}
  93.     idm_TopToolbar   = 701;
  94.     idm_LeftToolbar  = 702;
  95.     idm_RightToolbar = 703;
  96.     idm_About        = 704;
  97.  
  98.     {*** Speaks for itself ***}
  99.     AppName : PChar  = 'MDITool';
  100.  
  101. type
  102.  
  103.     PAboutDialog = ^TAboutDialog;
  104.     TAboutDialog = object(TMWCCDialog)
  105.         {***
  106.  
  107.             TMWCCBmpButton is a BWCC style bitMap button object. TMWCCStatic is a static object
  108.             that displays either raised, recessed or normal static controls. WMDrawItem is required
  109.             to draw the TMWCCBmpButton ownerdraw button object.
  110.  
  111.         ***}
  112.         OkBut        : PMWCCBmpButton;
  113.         Stat1, Stat2 : PMWCCStatic;
  114.         constructor Init (AParent: PWindowsObject; AName, ABmp: PChar);
  115.         procedure SetUpWindow; virtual;
  116.         procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
  117.     end;
  118.  
  119.     PMDIButton = ^TMDIButton;
  120.     TMDIButton = object(TMWCCBmpButton)
  121.         {***
  122.  
  123.             This object declares the buttons as non-MDI so they can be displayed as buttons.
  124.  
  125.         ***}
  126.         constructor Init (AParent: PWindowsObject; AnID, X, Y: Integer;
  127.                                             IsDefault: Boolean; iBmp: Integer; AStyle: Word);
  128.         procedure DefWndProc(Var Msg : TMessage); Virtual;
  129.     end;
  130.  
  131.     PMDIStatic = ^TMDIStatic;
  132.     TMDIStatic = object(TMWCCStatic)
  133.         {***
  134.  
  135.             This object declares the static as non-MDI so it can be displayed as a static.
  136.  
  137.         ***}
  138.         constructor Init (AParent: PWindowsObject; AnId: Integer; ATitle: PChar;
  139.                                             X, Y, W, H: Integer; ATextLen, AShade: Word; IsBold: Boolean);
  140.     end;
  141.  
  142.     PMDIChild = ^TMDIChild;
  143.     TMDIChild = object(TWindow)
  144.         {***
  145.  
  146.             This MDI Child to shows off the new TMWCCFontDlg common font dialog box.
  147.  
  148.         ***}
  149.         TheFont : HFont;
  150.         constructor Init(AParent: PWindowsObject; AName: PChar);
  151.         procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  152.         procedure WMPaint (var Msg: TMessage); virtual wm_First + wm_Paint;
  153.     end;
  154.  
  155.     PMDITool = ^TMDITool;
  156.     TMDITool = object(TMDIWindow)
  157.         BkBrush : HBrush;
  158.         But1, But2, But3, But4, But5, But6 : PMDIButton;
  159.         Stat1 : PMWCCStatic;
  160.         X, Y, W, H : Integer;
  161.         ToolbarPos : Word;
  162.         constructor Init (ATitle : PChar; AMenu : HMenu);
  163.         destructor Done; virtual;
  164.         function GetClassName : PChar; virtual;
  165.         function InitChild : PWindowsobject; virtual;
  166.         procedure GetWindowClass (var AWndClass: TWndClass); virtual;
  167.         procedure SetUpWindow; virtual;
  168.         procedure InitClientWindow; virtual;
  169.         procedure WMCtlColor (var Msg: TMessage); virtual wm_First + wm_CtlColor;
  170.         procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
  171.         procedure WMSize (var Msg: TMessage); virtual wm_First + wm_Size;
  172.         procedure TopToolbar(var Msg: TMessage); virtual;
  173.         procedure LeftToolbar(var Msg: TMessage); virtual;
  174.         procedure RightToolbar(var Msg: TMessage); virtual;
  175.         procedure IDMTopToolbar (var Msg: TMessage); virtual cm_First + idm_TopToolbar;
  176.         procedure IDMLeftToolbar (var Msg: TMessage); virtual cm_First + idm_LeftToolbar;
  177.         procedure IDMRightToolbar (var Msg: TMessage); virtual cm_First + idm_RightToolbar;
  178.         procedure IDMAbout (var Msg: TMessage); virtual cm_First + idm_About;
  179.         procedure IDWBut1 (var Msg: TMessage); virtual id_First + idw_But1;
  180.         procedure IDWBut2 (var Msg: TMessage); virtual id_First + idw_But2;
  181.         procedure IDWBut3 (var Msg: TMessage); virtual id_First + idw_But3;
  182.         procedure IDWBut4 (var Msg: TMessage); virtual id_First + idw_But4;
  183.         procedure IDWBut5 (var Msg: TMessage); virtual id_First + idw_But5;
  184.         procedure IDWBut6 (var Msg: TMessage); virtual id_First + idw_But6;
  185.     end;
  186.  
  187.     PMDIToolApplication = ^TMDIToolApplication;
  188.     TMDIToolApplication = object(TApplication)
  189.         procedure InitMainWindow; virtual;
  190.     end;
  191.  
  192. var
  193.  
  194.     ColorRef : TColorRef;
  195.     HLib     : THandle;
  196.     {*** TLogFont Structure ***}
  197.     LogFont  : TLogFont;
  198.  
  199. {********** TMDIToolApplication **********}
  200.  
  201. procedure TMDIToolApplication.InitMainWindow;
  202. begin
  203.     MainWindow := New(PMDITool, Init('MDITool', LoadMenu(HInstance, 'MDIToolMenu')));
  204. end;
  205.  
  206. {********** TMDITool **********}
  207.  
  208. constructor TMDITool.Init(ATitle : PChar; AMenu : HMenu);
  209. begin
  210.     TMDIWindow.Init(ATitle, AMenu);
  211.     {***
  212.  
  213.         This sets the error mode so that if MWCC.dll is not found a normal messagebox gets
  214.         diplayed (rather than an ugly white one). The error mode is then reset to the default.
  215.  
  216.     ***}
  217.     SetErrorMode(SEM_NoOpenFileErrorBox);
  218.     hLib := LoadLibrary ('MWCC.dll');
  219.     if hLib < 32 then
  220.     begin
  221.         MessageBox(0, 'Cannot find MWCC.DLL in your Windows System subdirectory.',
  222.                                     'Application Error', mb_Ok or mb_IconStop);
  223.         TerminateApp(0, No_UAE_Box);
  224.     end;
  225.     SetErrorMode(0);
  226.     Attr.X := GetSystemMetrics(sm_CXScreen) div 8;
  227.     Attr.Y := GetSystemMetrics(sm_CYScreen) div 8;
  228.     Attr.W := (GetSystemMetrics(sm_CXScreen) div 8)*6;
  229.     Attr.H := (GetSystemMetrics(sm_CYScreen) div 8)*5-4;
  230.     {*** The buttons are initialized with the dummy values and repositioned later in WMSize ***